import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class preCreateTree extends BinaryTree{
    public List<Character> preTree(TreeNode root) {
        List<Character> list = new ArrayList<>();
        if (root == null) {
            return list;
        }
        Stack<TreeNode> stack = new Stack<>();
        TreeNode cur = root;
        while (cur != null || stack.isEmpty()) {
            while (cur != null){
                stack.push(cur);
            list.add(cur.val);
            cur = cur.left;
            }
        TreeNode top = stack.pop();
        cur = top.right;
        }
        return list;
    }
}
